<script type="text/javascript" language="javascript">
function show()
{
	document.nnf.action="index.php?tc=blog_add";
	document.nnf.submit();
}
</script>
<script type="text/javascript">
function SetChecked(val) 
{
	
	dml = document.form1;
	len = dml.elements.length;
	var i=0;
	for( i=0 ; i<len ; i++) 
	{
		if (dml.elements[i].id=='chk') 
			{	
			dml.elements[i].checked=val;}
	}
}
</script>
<?php
/*=========Delete selected Blog===============*/
if(isset($_REQUEST['DeleteBlog']))
{
	$count=mysql_num_rows(mysql_query("select * from blog_reply order by id DESC"));
	for($i=0;$i<$count;$i++)
	{
		$del_id = $_POST['chk'][$i];
		$sql = "DELETE FROM blog_reply WHERE id ='$del_id'";
		$result = mysql_query($sql);
	}
	if($result)
	echo "<script>window.location='index.php?tc=blogreply&info=".$_GET['info']."&mgs=Successfully Removed'</script>";
	//header("location: index.php?tc=blogreply&info=".$_GET['info']."&mgs=Successfully Removed");
}
/*=========Activate selected Blog===============*/
if(isset($_REQUEST['ActivateBlog']))
{
	$count=mysql_num_rows(mysql_query("select * from blog_reply order by id DESC"));
	for($i=0;$i<$count;$i++)
	{
		$del_id = $_POST['chk'][$i];
		$sql = "update blog_reply set status='1' WHERE id ='$del_id'";
		$result = mysql_query($sql);
	}
	if($result)
	echo "<script>window.location='index.php?tc=blogreply&info=".$_GET['info']."&mgs=Successfully Activated'</script>";
	//header("location: index.php?tc=blogreply&info=".$_GET['info']."&mgs=Successfully Activated");
}
/*=========DeActivate selected Blog===============*/
if(isset($_REQUEST['DeactivateBlog']))
{
	$count=mysql_num_rows(mysql_query("select * from blog_reply order by id DESC"));
	for($i=0;$i<$count;$i++)
	{
		$del_id = $_POST['chk'][$i];
		$sql = "update blog_reply set status='0' WHERE id ='$del_id'";
		$result = mysql_query($sql);
	}
	if($result)
	echo "<script>window.location='index.php?tc=blogreply&info=".$_GET['info']."&mgs=Successfully De-activated'</script>";
	//header("location: index.php?tc=blogreply&info=".$_GET['info']."&mgs=Successfully De-activated");
}
?>
<form name="nnf" method="post" action="#">
<table border="0" width="100%" align="center">
<tr>
	<td width="45%" align="left"><span style="color:#1B78B7; font-size:14px; font-weight:bold">Blog Reply</span></td>
	<td width="40%" align="right">&nbsp;
    </td>
	<td width="15%" align="right"><select name="_st" onchange="window.location='index.php?tc=blogreply&page=<?php echo $_REQUEST['page'];?>&info=<?php echo $_GET['info']?>&_st='+this.value">
	  <option value="" <?php if($_REQUEST['_st']=="") echo "selected";?>><--Sort--></option>
	  <option value="2" <?php if($_REQUEST['_st']==2) echo "selected";?>>All</option>
	  <option value="1" <?php if($_REQUEST['_st']==1) echo "selected";?>>Active Blog</option>
	  <option value="0" <?php if($_REQUEST['_st']==3) echo "selected";?>>Deactive Blog</option>
	  </select></td>
</tr>
<tr>
	<td background="images/topline.gif" colspan="3" height="11"></td>
</tr>    
</table>
</form>
<?php
if($_REQUEST['_s'] == 2)
{ ?>
	<table align="center" border="0">
	<tr>
    	<td align="center"><div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;Deleted Successfully</div></td>
    </tr>    
    </table>
<?php } ?>
<?php
if(isset($_GET['mgs']))
{ ?>
	<table align="center" border="0">
	<tr>
    	<td align="center"><div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;<?php echo $_GET['mgs'];?></div></td>
    </tr>    
    </table>
<?php } ?>
<form id="form1" name="form1" method="post" action="#">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="3%" align="left" valign="middle">
    <a href="javascript:SetChecked(1)" class="font12"><img src="../img/checkbox.png" title="Check All" border="0" /></a></td>
    <td width="3%" align="left" valign="middle">
    <a href="javascript:SetChecked(0)" class="font12"><img src="../img/checkbox_no.png" border="0" title="Uncheck All" /></a>
    </td>
    <td width="94%" align="left" valign="middle">
    <input type="submit" name="ActivateBlog" class="buttonbg"  value="Activate"/>
    <input type="submit" name="DeactivateBlog" class="buttonbg"  value="De-activate"/>
    <input type="submit" name="DeleteBlog" class="buttonbg"  value="Delete"/>
    </td>
  </tr>
</table>
<table width="100%" align="center" border="0" class="list">
<thead>
<tr>
	<td colspan="2" align="center">#</td>
	<td width="626" align="center">Comments</td>
    <td align="center" width="150">Status</td>
    <td align="center" width="126">Submitted Date</td>
    <td width="153" align="center">Action</td>
</tr>
</thead>
<?php
include('includes/function.php');
$self="index.php?tc=blogreply&_st=".$_REQUEST['_st'];
$rowsPerPage = 20;
$pageNum = 1;
if(isset($_GET['page']))
{
	$pageNum = $_GET['page'];
}
if($_GET['page']=="")
{
	$pageNum = 1;
}

/*<!--counting the offset-->*/
$offset = ($pageNum - 1) * $rowsPerPage;
$st = $_REQUEST['_st'];

/*if($st == "" || $st == 2)
{
	$res = mysql_query("select Id from users");
	
	$query = mysql_query("select Id,Organisation, Title, Category, DATE_FORMAT(CreatedDate,'%d-%m-%Y') as insdate, Status from news order by Id desc limit $offset , $rowsPerPage") or die(mysql_error());
}
else
{
	if($st == 3) $st=0;
	$res = mysql_query("select Id from users where Status='$st'");
	
	$query = mysql_query("select Id,Organisation, Title, Category, DATE_FORMAT(CreatedDate,'%d-%m-%Y') as insdate, Status from news where Status='$st' order by Id desc limit $offset , $rowsPerPage");
}*/
if($st == "" || $st == 2)
{
	$str="select id, comments, status, DATE_FORMAT(postdate,'%d-%m-%Y') as insdate from blog_reply where blogid='".$_GET['info']."' order by id desc limit $offset , $rowsPerPage";
}
else
{
	$str = "select id, comments, status, DATE_FORMAT(postdate,'%d-%m-%Y') as insdate from blog_reply where blogid='".$_GET['info']."' and status='".$st."' order by id desc limit $offset , $rowsPerPage";
}
$query = mysql_query($str);
$i = 1;
while($q = mysql_fetch_array($query))
{ 
	if($q["status"] == 1) 
	$status = "Active";
	else 
	$status = "Deactive";
	?>
    <tr>
        <td width="23" align="center">
        <input type="checkbox" name="chk[]" id="chk" value="<?php echo $q['id']?>"/>
        </td>
        <td width="23" align="center"><?php echo $i+$offset;?></td>
        <td align="left"><?php echo $q["comments"];?></td>
        <td align="center"><?php echo $status;?></td>
        <td align="center"><?php echo $q['insdate'];?></td>
        <td align="center"><a href="index.php?tc=blog_view&_d=<?php echo $q['id'];?>&page=<?php echo $pageNum;?>">View</a> | 
        	<a href="index.php?tc=blog_view&_d=<?php echo $q['id'];?>&_a=d&page=<?php echo $pageNum;?>" onclick="return confirm('Are you sure want to delete?')">Delete</a>
        </td>
   	</tr>     
<?php 
	$i++;
}
$tots=mysql_num_rows($query);
if($tots<=0){
?>
<tr>
    <td colspan="6" align="center"  bgcolor="#E3ECF3">
        ~ No Record Found ~
    </td>
</tr>
<?php
}
if(mysql_num_rows($query) <= $rowsPerPage){	}
else { ?>
<tr>
    <td colspan="6" align="center"  bgcolor="#E3ECF3">
        <?php echo $paginglink=getPagingLink($res, $rowsPerPage,$pageNum,$self); ?>	
    </td>
</tr>
<?php } ?>
</table>
</form>    